package com.sciencep.pro.core.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sciencep.pro.common.config.Constant;
import com.sciencep.pro.core.dao.ProNodeMapper;
import com.sciencep.pro.core.domain.dto.project.ProNodeTO;
import com.sciencep.pro.core.domain.entity.ProNode;
import com.sciencep.pro.core.service.IProNodeService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Sciencep
 */
@Service
public class ProNodeServiceImpl extends ServiceImpl<ProNodeMapper, ProNode> implements IProNodeService {


    @Override
    public List<ProNodeTO> getProNodeList(String typeId) {

        List<ProNode> nodes = this.list(new LambdaQueryWrapper<ProNode>().eq(typeId != null, ProNode::getTypeId, typeId).eq(ProNode::getIsDel, Constant.IsDelete.NO));
        if (CollUtil.isEmpty(nodes)) {
            return new ArrayList<>();
        }
        List<ProNodeTO> result = new ArrayList<>();
        nodes.forEach(o ->
                result.add(new ProNodeTO().setNodeName(o.getNodeName()).setNodeId(String.valueOf(o.getId())))
        );

        return result;
    }
}
